package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.PersonDao;
import com.itheima.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = PersonService.class)
@Transactional
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonDao personDao;
    @Override
    public List<List<Object>> findStatusCountByMonths(List<String> months) {

        List<List<Object>> source = new ArrayList<>();
        for (String month : months) {
            Map<String,String> map = new HashMap<>();
            map.put("startDate",month+".1");
            map.put("endDate",month+".31");
            List<Object> statusCountByMonths =new ArrayList<>();
            statusCountByMonths.add(month);
            List<Integer> counts = personDao.findStatusCountByMonths(map);
            for (Integer count : counts) {
                statusCountByMonths.add(count);
            }
            source.add(statusCountByMonths);
        }
        return source;
    }

}
